package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Order;
import service.OrderManager;
import service.impl.OrderManagerFactory;

public class BuyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private OrderManager orderManager;
       
    public BuyServlet() {
        super();
        orderManager = OrderManagerFactory.getInstance();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<Order> orders = (List<Order>) request.getSession().getAttribute("order");
		for(Order order:orders){
			order.setBuyTime(new Date());
			System.out.println(order.getId()+order.getUid()+order.getBid()+order.getNum()+order.getBuyTime());
			if(order.getNum()!=0){
				int m = orderManager.addOrder(order);
				System.out.println(m+"~~~~~~~~~~~");
			}
		}
		PrintWriter writer = response.getWriter();
		writer.write("Successful!");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
